package cn.funeralobjects.project.sshd.server;

import cn.funeralobjects.project.sshd.config.properties.SshProperties;
import org.apache.sshd.server.SshServer;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author FuneralObjects
 * Create date: 2020/8/5 4:29 AM
 */
public class SshApplication implements SmartLifecycle {

    private SshServer sshServer;

    public void setSshServer(SshServer sshServer) {
        this.sshServer = sshServer;
    }

    @Override
    public void start() {
        System.out.println("starting....");
        try {
            sshServer.start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void stop() {
        try {
            sshServer.stop();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean isRunning() {
        return sshServer.isStarted();
    }

}
